package com.jiangyao.common.utils;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class MathUtil {
    /**
     * 两个整数相除，并保留对应小数位数
     * @param num1
     * @param num2
     * @param keep -保留位数
     * @return
     */
    public static double divisionKeep(int num1,int num2,int keep){
        if(num2==0){
            return 0;
        }
        BigDecimal bi1 = new BigDecimal(String.valueOf(num1));
        BigDecimal bi2 = new BigDecimal(String.valueOf(num2));
        BigDecimal divide = bi1.divide(bi2, keep, RoundingMode.HALF_UP);
        return divide.doubleValue();
    }
}
